package com.fyf.game.net.server;

import com.fyf.game.net.NioUtil;
import com.fyf.game.net.Sender;
import com.fyf.game.net.SenderBox;

/**
 * @author fanyifeng
 */
public class MsgSender implements Sender
{
	private DataManager	mgr;
	private String		id;
	private String		name;
	private SenderBox	box;

	public MsgSender(DataManager mgr, SenderBox box) {
		this.mgr = mgr;
		this.box = box;
	}

	public void setID(String id) {
		this.id = id;
	}

	public void send(String msg) {
		mgr.put(msg);
	}

	public String getID() {
		return id;
	}

	public SenderBox getBox() {
		return box;
	}

	public void distroy() {
		box.remove(id);
		NioUtil.cancelAndClose(mgr.getKey());
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getName() {
		return name == null ? id : name;
	}
}
